package com.jike.noobmoney.mvp.view.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.TopMouthAdapter;
import com.jike.noobmoney.contants.ConstantValue;
import com.jike.noobmoney.entity.GoldPromotionEntity;
import com.jike.noobmoney.mvp.presenter.TaskPresenter;
import com.jike.noobmoney.net.IView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Create by xuke on 2019/02/28
 * 上月排行榜
 */
public class RankMouthTwoActivity extends BaseActivity implements IView {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    private TaskPresenter taskPresenter;
    private TopMouthAdapter topInviteAdapter;

    private List<GoldPromotionEntity.InviteweekrankBean> mData = new ArrayList<>();

    @Override
    protected int layoutResID() {
        return R.layout.activity_mouth_rank;
    }

    @Override
    protected void initData() {
        tvTitle.setText("上月排行榜");
        taskPresenter = new TaskPresenter(this);

        topInviteAdapter = new TopMouthAdapter(context);
        recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
        recyclerView.setAdapter(topInviteAdapter);

        getData();
    }
    /**
     * 如果要全屏,重写这个方法返回false
     */
    public Boolean isfits() {
        return true;
    }

    /**
     * 如果要白色主题,重写这个方法返回false
     */
    public boolean ismain() {
        return true;
    }
    /**
     * 获取数据
     */
    private void getData() {
        showProgress();
        taskPresenter.getInviteList("1", "1", ConstantValue.RequestKey.top_invite);
    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        dismissProgress();
        if (ConstantValue.RequestKey.top_invite.equals(actionType)) {
            List<GoldPromotionEntity.InviteweekrankBean> goldpromotionlist = (List<GoldPromotionEntity.InviteweekrankBean>) data;
            if (goldpromotionlist != null && goldpromotionlist.size() > 0) {
                mData.clear();
                mData.addAll(goldpromotionlist);
            }
            topInviteAdapter.refresh(mData);
        }

    }

    @Override
    public void onFailed(String code, String msg) {
        dismissProgress();
    }
}
